<template>
	<view class="add-withdrawal-account">
		<!-- 添加提现账户 3-->
		<u-navbar leftIconSize="34rpx" autoBack :placeholder="true" bgColor="#ffffff">
			<view slot="center">
				<text class="c-000 pf-sc fw-600" style="font-size: 34rpx;">添加提现账户</text>
			</view>
		</u-navbar>
		<view
			class="authentication-container w-750 b-box  bg-fa po-re"
			:style="{ height: containerHeight }"
		>
			<view
				class="d-flex flex-r ali-i-c just-s b-box w-100 bg-ff"
				style="padding: 36rpx 32rpx 34rpx;border-bottom: 1rpx solid #eaeaea;"
			>
				<text
					class="pf-sc fw-400"
					style="font-size: 30rpx;color: rgba(0,0,0,0.9000);margin-right: 48rpx;"
				>
					姓名
				</text>
				<u-input
					border="none"
					placeholder="请输入真实姓名，需要与认证信息一致"
					:customStyle="{ color: 'rgba(0,0,0,0.9000)', font: '400 30rpx PingFang SC' }"
					placeholderStyle="color:#999999;fontWeight:400;fontsize:30px;fontfamily:PingFang SC-Regular, PingFang SC"
					v-model="datainfo.name"
				></u-input>
			</view>
			<!--  -->
			<view
				class="d-flex flex-c ali-i-s just-s b-box w-100 bg-ff"
				style="padding: 36rpx;margin-bottom: 80rpx;"
			>
				<text
					class="fw-400 pf-sc"
					style="font-size: 30rpx;color:rgba(0,0,0,0.9000);margin-bottom: 20rpx;"
				>
					微信收款码：
				</text>

				<image
					@click="chooseimg"
					v-if="datainfo.txcode"
					:src="'https://www.chejingjing.cn/' + datainfo.txcode"
					mode="widthFix"
					style="width: 126rpx;height: 126rpx;"
				></image>
				<image
					v-else
					:src="require('@/static/add.png')"
					mode="widthFix"
					style="width: 126rpx;height: 126rpx;"
					@click="chooseimg"
				></image>
			</view>
			<!--  -->
			<view class="w-100 b-box d-flex flex-r ali-i-c just-c">
				<u-button
					:throttleTime="700"
					@click="Withdrawal"
					:customStyle="{
						height: '88rpx',
						width: '670rpx',
						font: '400 32rpx PingFang SC',
						color: '#ffffff',
						borderWidth: '0rpx',
						background: 'linear-gradient(180deg, #4885C5 0%, #3B52A6 100%)',
						borderRadius: '44rpx'
					}"
					shape="square"
					text="保存"
				></u-button>
			</view>
		</view>
	</view>
</template>

<script>
import { _containerHeight, _addUnit, _rpxTpx } from '@/utils/GetSys.js';
import Unavbar from '../components/uview-ui/components/u-navbar/u-navbar';
import Ubutton from '../components/uview-ui/components/u-button/u-button';
import uInput from '../components/uview-ui/components/u-input/u-input';
import { txcode } from '@/common/api.js';

export default {
	components: {
		'u-navbar': Unavbar,
		'u-button': Ubutton,
		'u-input': uInput
	},
	data() {
		return {
			containerHeight: '',
			datainfo: {
				name: '',
				txcode: ''
			},
			img: ''
		};
	},
	methods: {
		getindexcont() {
			txcode({
				token: uni.getStorageSync('user').token
			})
				.then(res => {
					if (res.data.code === 1) {
						this.datainfo = res.data.data;
						console.log(this.datainfo);
					}
				})
				.catch(err => {});
		},
		Withdrawal() {
			if (!this.datainfo.name) {
				return uni.showToast({
					title: '请输入您的真实姓名',
					icon: 'none'
				});
			}
			if (!this.datainfo.txcode) {
				return uni.showToast({
					title: '请上传您的微信收款码',
					icon: 'none'
				});
			}
			//前往提现
			txcode({
				token: uni.getStorageSync('user').token,
				name: this.datainfo.name,
				txcode: this.datainfo.txcode
			}).then(res => {
				if (res.data.code === 1) {
					uni.showToast({
						title: '保存成功',
						icon: 'success'
					});
					setTimeout(() => {
						uni.navigateTo({
							url: '/staffModelA/staffC/ImmediatelyWithdrawal/ImmediatelyWithdrawal'
						});
					}, 1000);
				}
			});
		},
		chooseimg() {
			let _this = this;
			uni.chooseImage({
				count: 1,
				success: res => {
					console.log(res.tempFilePaths);
					this.img = res.tempFilePaths[0];
					uni.uploadFile({
						url: 'https://www.chejingjing.cn/api/index/uploadimg',
						filePath: res.tempFilePaths[0],
						name: 'photo',
						success(res1) {
							_this.datainfo.txcode = JSON.parse(res1.data).data.url1;
						}
					});
				}
			});
		}
		// async afterRead(event) {
		// 	let lists = [].concat(event.file);
		// 	let fileListLen = this[`fileList${event.name}`].length;
		// 	lists.map(item => {
		// 		this[`fileList${event.name}`].push({
		// 			...item,
		// 			status: 'uploading',
		// 			message: '上传中'
		// 		});
		// 	});
		// 	for (let i = 0; i < lists.length; i++) {
		// 		const result = await this.uploadFilePromise(lists[i].url);
		// 		let item = this[`fileList${event.name}`][fileListLen];
		// 		this[`fileList${event.name}`].splice(
		// 			fileListLen,
		// 			1,
		// 			Object.assign(item, {
		// 				status: 'success',
		// 				message: '',
		// 				url: result
		// 			})
		// 		);
		// 		fileListLen++;
		// 	}
		// },
		// deletePic(event) {
		// 	this[`fileList${event.name}`].splice(event.index, 1);
		// }
	},
	onLoad() {
		this.containerHeight = _containerHeight();
		this.getindexcont();
	}
};
</script>

<style lang="scss">
.add-withdrawal-account {
}
</style>
